﻿<style>
    th span{white-space:normal;line-height:19px;}
    .layui-table-view .layui-table td, .layui-table-view .layui-table th{
        padding:2px 0px;
    }
    .layui-table-cell {overflow-x: hidden;overflow: inherit;line-height:19px; padding: 3px 0px;text-align:center}
    .layui-table-box {
        overflow: inherit;
    }
    .redclass{color:red;}
    .layui-table-body {
        overflow: inherit;
    }
    .diy-brown{color:#c28736}
    .layui-input{height:30px;}
    .layui-form-pane .layui-form-label{width:auto;}
    .layui-form-pane .layui-input{height:38px;}
    .layui-input-inline{width:130px;}
</style>
<div class="fixed-bar">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('')}" method="get" id="hisi-table-search">
        <div class="layui-inline">
            <label class="layui-form-label">订单号</label>
            <div class="layui-input-inline">
                <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
            </div>
        </div>
        <div class="layui-inline sku_input_search">
            <label class="layui-form-label">sku</label>
            <div class="layui-input-inline">
                <input type="text" name="sku" lay-verify="" placeholder="输入sku" class="layui-input">
            </div>
        </div>
        <div class="layui-inline removeStat">
            <label class="layui-form-label">单类</label>
            <div class="layui-input-inline">
                {:Form::select('type', '', [''=>'全部','normal'=>'返单','new'=>'首单','emergent'=>'紧急单','my_first'=>'（奖励）第一次做(不含尾货)','my_return_first'=>'初返（不含尾货）'], '', '')}
            </div>
        </div>
        <div class="layui-inline factory_serarch_input">
            <label class="layui-form-label">工厂</label>
            <div class="layui-input-inline">
                {:Form::select('factory_id', '', $factoryKV, '', '')}
            </div>
        </div>
        <div class="layui-inline searchSubmit">
            <button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
        </div>
    </form>
</div>
<table id="dataTable" lay-filter="demoEvent"></table>

{include file="system@block/layui" /}
<script type="text/html" id="toolbar">
</script>

<script type="text/html" id="skuimgTpl">
    <span class="lay-pic-container" src="{{ d.ori_pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
	</span>
</script>
<script type="text/html" id="OrdernumTpl_red">
    <span class="copy-item">{{ d.client_ordernum }}</span>  /
    <br>
    <span class="copy-item">{{ d.sku }}</span>
</script>

<script type="text/html" title="操作按钮模板" id="MesTpl1">
   {{# if(d.mes_status_now == 0 || d.mes_status_now == 1 || d.mes_status_now == 2  ||  d.mes_status_now == 3 || d.mes_status_now == 4 ){ }}
      <a  class="diy-brown copy-item" lay-event="mesSkuDff"   data-status="{{d.mes_status_now}}" data-copy="{{ d.client_ordernum}}" data-sku="{{ d.client_ordernum}}" >{{d.mes_status}}</a>
   {{# }else{ }}
         {{d.mes_status}}
   {{# } }}
</script>
<script type="text/html" title="操作按钮模板" id="MesTpl2">
    {{# if(d.url !=''){ }}
         <a  class="diy-brown copy-item" lay-event="mesStatusDff" data-url="{{d.url}}" data-copy="{{ d.client_ordernum}}" data-sku="{{ d.client_ordernum}}" >{{d.local_status}}</a>
    {{# }else{ }}
        {{d.local_status}}
    {{# } }}
</script>

<script type="text/javascript">
    layui.use(['opTable','table','jquery', 'tool', 'form','laydate', 'layer'], function() {
        var $ = layui.jquery;
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        form.render();
        table.render({
            elem: '#dataTable'
            ,url: "{:url('diffStatus')}" //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: true
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                {field:'order_sku',title : '订单号/SKU',templet: '#OrdernumTpl_red',width:120}
                ,{field:'ori_pic',title : '图片',templet:'#skuimgTpl',width:90}
                ,{field:'order_from',title : '账号',width:60}
                ,{field:'type',title : '订单类型',width:60}
                ,{field:'mes_status',title : '订单状态/MES系统',templet: '#MesTpl1',width:110}
                ,{field:'local_status',title : '订单状态/数据中心',templet: '#MesTpl2',width:110}
                ,{field:'factory_name',title : '工厂',width:100}
                ,{field:'showStatus',title : '状态',width:70}
                ,{field:'client_status_sync_time',title : '最后同步时间',width:140}
            ]]
            ,done: function (res) {

            }
        });

        //按钮：去mes修改
        table.on('tool(demoEvent)', function(obj){
            var parm=[],
                d = obj.data; //得到所在行所有键值
            //修改状态
            obj.update({
                showStatus: '已修正-待同步'
            });
            $.ajax({
                type: "POST",
                url: "{:url('diffStatus')}",
                data: "client_ordernum="+d.client_ordernum+"&action="+"setSyncStatus",
                dataType:"json",
                success: function(res){
                    layer.msg('已修改', {icon: 1});
                }
            });

            if(obj.event === 'mesSkuDff') {
               var statusNow= $(this).attr("data-status");
                setTimeout(function() {
                    if(statusNow==2){
                        window.open("https://www.020mes.com/#/future/factory/schedule-produce/cutbed");
                    }else if(statusNow==3){
                        window.open("https://www.020mes.com/#/future/factory/schedule-produce/sewing");
                    }else if(statusNow==4){
                        window.open("https://www.020mes.com/#/future/factory/schedule-produce/ironing");
                    }else if(statusNow==0 || statusNow==1){
                        window.open("https://www.020mes.com/#/future/factory/order/list");
                    }
                }, 1500);//1.5秒后跳转
            }
            if(obj.event === 'mesStatusDff') {
                var url='http://'+$(this).attr("data-url");
                setTimeout(function() {
                    window.open(url);
                }, 1500);//1.5秒后跳转
            }
        });
    });
</script>